<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>TAF Project : NIIK1 OFFICE</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta content="ru" name="content-language"/>

    <link type="text/css" href="js/jquery-ui-1.8.17.custom.css" rel="stylesheet"/>
    <link type="text/css" href="js/search_results.css" rel="stylesheet"/>
    
    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script>
    <script type="text/javascript" src="js/jquery.ui.datepicker-ru.js"></script>
    
    <script type='text/javascript'>
        $(document).ready(function(){
            $("#search_results").slideUp();

            $("#search_form").submit(function(s){
                s.preventDefault();
                if ($('input#only_last_rev').attr('checked'))
                    only_last_rev = 1;
                else
                    only_last_rev = 0;
                search();
            });
            
            $("#button_clear").click(function(s){
                s.preventDefault();
                clear();
            });
            
            $("#button_get").click(function(s){
                s.preventDefault();
                check_server();
            });
            
            $("#button_update").click(function(s){
                s.preventDefault();
                update_comments();
            });
            
            $("#button_answer").click(function(s){
                s.preventDefault();
                write_answer_to_word();
            });

            // ---- Календарь -----
            $('input[id^="date"]').datepicker();
            
            //Начальные параметры сортировки
            sort_by = 'drawing';
            sort_direction = 'ASC';
            
            //Алгоритм сортировки
            $('a#sort').click(function(s){
                s.preventDefault();
                if (sort_by == $(this).attr('href')) 
                    if (sort_direction == 'ASC') sort_direction = 'DESC';
                    else sort_direction = 'ASC';
                sort_by = $(this).attr('href');
                search();
            });
            
            

        });

        

        function clear(){
            $("#search_form").find("input:text").val('');
            $("#project").val('6417');
            $("#drawing").focus();
        }
        
        function write_answer_to_word() {
          $("#get_bar").show();
          $("#get_bar").html('Please, wait...');
          $.post("./php/write_answer_to_word.php",{ 
              answer_in : $("#answer_in").val(),
              answer_out : $("#answer_out").val()
          }, function(data){ $("#get_bar").html(data); });
        }
        
        function change(uin,atr_name,atr_value) {
          $("#get_bar").show();
          $("#get_bar").html('');
          $.post("./php/change.php",{ 
              uin : uin,
              atr_name : atr_name,
              atr_value : atr_value
          }, function(data){ $("#get_bar").html(data); });
        }
        
        function check_server() {
          $("#check_bar").html('Please, wait...'); 
          $.post("./php/check_server.php", function(data){
              $("#check_bar").html(data); 
              //Внесение изменений в свойства
                $('a#transmittal').click(function(s){
                    s.preventDefault();
                    var transmit = $(this).attr('href');
                    get_T_from_server(transmit);
                });
          });
          
        }
        
        function get_T_from_server(transmit) {
          $("#get_bar").html('Please, wait...'); 
          $.post("./php/get_T_from_server.php", {transmit : transmit},
            function(data){ $("#get_bar").html(data); });
        }
        
        function update_comments() {
          $("#check_bar").html('Please, wait...');
          $.post("./php/update_comments.php", function(data){ $("#check_bar").html(data); });
        }
        
        
        function search(){
          $("#search_results").show();
          $("#search_results").html('Loading..<br>');
          
          $.post("./php/search.php",{ 
              project : $("#project").val(),
              drawing : $("#drawing").val(),
              revision : $("#revision").val(),
              part : $("#part").val(),
              status : $("#status").val(),
              title : $("#title").val(),
              date_in_beg : $("#date_in_beg").val(),
              date_in_end : $("#date_in_end").val(),
              transmit_in : $("#transmit_in").val(),
              date_out_beg : $("#date_out_beg").val(),
              date_out_end : $("#date_out_end").val(),
              transmit_out : $("#transmit_out").val(),
              checked : $("select#checked").val(),
              aproved : $("select#aproved").val(),
              comments : $("#comments").val(),
              sort_by : sort_by,
              sort_direction : sort_direction,
              only_last_rev : only_last_rev
          }, function(data){
           if (data.length>0){
             $("#search_results").html(data);
             
             //Внесение изменений в свойства
            $('.property[type=checkbox]').click(function(){
                var uin = $(this).attr('name');
                var value = $(this).attr('value');
                if (value == 0) value = 1; else value = 0;
                $(this).attr('value', value);
                change(uin,'checked',value);
            });
            
            //Проверка строк на обновления
            $('.actual').each(function(){

                $.ajax({
                  url: "./php/update_comment.php",
                  context: $(this),
                  type: "POST",
                  data: {uin : $(this).attr('name')},
                  success: function(data){
                    if (data == "TRUE")
                        $(this).children().attr('src','/img/warning.png');
                    if (data == "FALSE")
                        $(this).children().attr('src','/img/accepted.png');
                    
                  }
                });
                
            });
            
           }
          });
          
          
        }

    </script>




</head>

<body>

<div id="check_bar" align="center"></div>    
<div id="get_bar" align="center"></div>  
    
<div align="center">
    <table><tr>
        <td class="buttons"><input type="button" id="button_get" value="SERVER" title="Check server for new transmittals"/></td>
<!--        <td class="buttons"><input type="button" id="button_update" value="COMMENTS"/></td>-->
        <td class="buttons"><input type="button" id="button_answer" value="MAKE ANSWER" title="Prepare answer-letter in MS Word"/></td>
        <td class = "td_transmit"><input type="text" name="answer_in" id="answer_in" title="Incoming transmittal"/></td>
        <td class = "td_transmit"><input type="text" name="answer_out" id="answer_out" title="Outcoming transmittal"/></td>
    </tr></table>
    <form id="search_form" method="post" >
        <input type="submit" value="SEARCH"/>
        
        <table>
        <tr>
            <td class = "td_button"> <img src="./img/clear.jpg" width="32px" height="32px" id="button_clear" title="Clear selection"/></td>
            <td class = "td_project"><input type="text" name="project" id="project"/></td>
            <td class = "td_drawing"><input type="text" name="drawing" id="drawing" /></td>
            <td class = "td_revision">
                <input type="text" name="revision" id="revision"/>
                <input type="checkbox" name="only_last_rev" id="only_last_rev" title="Only last revisions"/>
            </td>
            <td class = "td_part"><input type="text" name="part" id="part" /></td>
            <td class = "td_status"><input type="text" name="status" id="status"/></td>
            <td class = "td_title"><input type="text" name="title" id="title" /></td>
            <td class = "td_date">
                <input type="text" name="date_in_beg" id="date_in_beg" title="from"/>
                <input type="text" name="date_in_end" id="date_in_end" title="to"/>
            </td>
            <td class = "td_transmit"><input type="text" name="transmit_in" id="transmit_in"/></td>
            <td class = "td_date">
                <input type="text" name="date_out_beg" id="date_out_beg" title="from"/>
                <input type="text" name="date_out_end" id="date_out_end" title="to"/>
            </td>
            <td class = "td_transmit"><input type="text" name="transmit_out" id="transmit_out"/></td>
            
            <td class = "td_checked" title="Checked or not?">
            <SELECT NAME="checked" id="checked">
                <OPTION VALUE="1">Y</OPTION>
                <OPTION VALUE="0">N</OPTION>
                <OPTION VALUE="NULL" selected>-</OPTION>
            </SELECT>
            </td>
            
            <td class = "td_aproved" title="Aproved or not?">
            <SELECT NAME="aproved" id="aproved">
                <OPTION VALUE="1">Y</OPTION>
                <OPTION VALUE="0">N</OPTION>
                <OPTION VALUE="NULL" selected>-</OPTION>
            </SELECT>
            </td>
            
            <td class = "td_comments"><input type="text" name="comments" id="comments" width="100%"/></td>
        </tr>
        <tr>
            <td/>
            <td align="center"><a id="sort" href="project">Project</a></td>
            <td align="center"><a id="sort" href="drawing">Drawing</a></td>
            <td align="center"><a id="sort" href="revision">Rev</a></td>
            <td align="center"><a id="sort" href="part">Part</a></td>
            <td align="center"><a id="sort" href="drw_status">Status</a></td>
            <td align="center"><a id="sort" href="title">Title</a></td>
            <td align="center"><a id="sort" href="date_in">Date_in</a></td>
            <td align="center"><a id="sort" href="transmit_in">TRANSM_in</a></td>
            <td align="center"><a id="sort" href="date_out">Date_out</a></td>
            <td align="center"><a id="sort" href="transmit_out">TRANSM_out</a></td>
            <td align="center"><a id="sort" href="checked">C</a></td>
            <td align="center"><a id="sort" href="aproved">A</a></td>
            <td align="center"><a id="sort" href="comments">Comments</a></td>
        </tr>
        
        </table>    
    </form>
</div>

<div id="search_results" align="center"></div>

</body>
</html> 